package com.penghaisoft.microwms.base.web.data.service.impl;

import com.penghaisoft.microwms.base.web.area.dao.MdAreaMapper;
import com.penghaisoft.microwms.base.web.data.service.IMdAreaService;
import com.penghaisoft.microwms.common.data.model.MdArea;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 业务逻辑实现类
 * </p>
 * 
 * @author
 * @createDate 
 **/
@Service("mdAreaService")
public class MdAreaServiceImpl extends BaseService implements IMdAreaService {
	@Resource
	private MdAreaMapper mdAreaMapper;

	/**
	 * 新增记录,需要做编码唯一性校验
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp create(MdArea mdArea){
		Resp resp = new Resp();
		int count = mdAreaMapper.addUniqueCheck(mdArea);
		if (count>0) {
			resp = fail("base.data.area.code.conflict");
		}else {
			mdAreaMapper.create(mdArea);
			resp = success();
		}
		return resp;
	}

	/**
	 * 删除记录（逻辑删除）
	 * @param mdArea
	 * @return
	 */
	@Override
	public Resp delete(MdArea mdArea){
		mdAreaMapper.delete(mdArea);
		return success();
	}

	/**
	 * 查询列表
	 * @param
	 * @param
	 * @return
	 */
	@Override
	public Pager<MdArea> findListByCondition(int page, int rows, MdArea condition){
		Pager<MdArea> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
//		没传flag默认查询非删除的
		List<MdArea> records = mdAreaMapper.queryList(pager,condition);
		long size = mdAreaMapper.queryCount(condition);
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	/**
	 * 查询单条
	 * @param id
	 * @return
	 */
	@Override
	public MdArea findById(String id){
		return mdAreaMapper.queryById(id);
	}

	/**
	 * 修改记录
	 * @param mdArea
	 * @return
	 */
	@Override
	public Resp update(MdArea mdArea){
		mdAreaMapper.updateBySelect(mdArea);
		return success();
	}

	
	@Override
	public List<MdArea> queryMdAreaAll(MdArea condition) {
		return mdAreaMapper.queryMdAreaAll(condition);
	}
	/**
	 * @Description 查询仓库下的区域
	 * @author jingz
	 */
	@Override
	public List<MdArea> queryAreasUnderWareHouse(MdArea condition) {
		return mdAreaMapper.queryAreasUnderWareHouse(condition);
	}
	
}
